package logic

import (
	"context"
	"tb/tbrpc/tbrpcclient"

	"tb/api/internal/svc"
	"tb/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCartListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartListLogic {
	return &CartListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CartListLogic) CartList(req *types.CartListRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	cartList, err := l.svcCtx.TbRpc.CartList(l.ctx, &tbrpcclient.CartListRequest{
		UserId:    req.UserId,
		ProductId: req.ProductId,
	})

	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}

	return &types.Response{
		Message: "购物车列表展示成功",
		Data:    cartList,
		Code:    200,
	}, nil
}
